import request from '../request'
import requestUrl from '../requestUrl'
import requestParam from '../requestParam'


export function jisuan(num) {
    return request({
    		headers: {"token": getCookie("token")},
        url: requestUrl("jisuan"),
        method: 'post',
        data: requestParam({"expression":"a*b","a":num,"b":0.025})
    })
}

//获取cookie、
export function getCookie(name) {
 var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
 if (arr = document.cookie.match(reg))
  return (arr[2]);
 else
  return null;
}

export function check(mess) {
    return request({
    		headers: {"token": mess.token},
        url: requestUrl(mess.url),
        method: 'post',
        data: requestParam(mess.info)
    })
}

export function upload(mess) {
    return request({
    		headers: {"token": mess.token},
        url: requestUrl(mess.url),
        method: 'post',
        data: mess.fileObj
    })
}

export function getKeyWordNum(mess) {
    var data = mess.replace(new RegExp('，','g'),',');
   	var arr = data.split(" ");
   	var num = '';
  	if(arr[arr.length-1] == ''){
  		num = arr.length-1
  	}else{
  		num = arr.length
  	}
  	return num;
}

export function editTaskName(mess) {
    return request({
    		headers: {"token": mess.token},
        url: requestUrl("modifyTaskName"),
        method: 'post',
        data: mess.Obj
    })
}

export function download(token,url) {
  return request({
		headers: {"token": token},
    	url: requestUrl(url),
    	method: 'get',
  })
}

export function urlPay(token,url) {
  return request({
		headers: {"token": token},
    	url: requestUrl(url),
    	method: 'get',
  })
}

//export function checkUrl(mess) {
//  return request({
//  		headers: {"token": mess.token},
//      url: requestUrl(mess.url),
//      method: 'post',
//      data: requestParam(mess.info)
//  })
//}